package com.psmz.iwi.docanalyzer.core.document.entities;

import java.io.File;
import java.util.Date;

/**
 * Dokument.
 * 
 * @author piotrs10
 * 
 */
public class Document {
	private Long id;
	private File file;
	private DocumentType type;
	private String name;
	private Date creationDate;
	private Date indexingDate = null;
	private boolean indexed = false;
	private Long numberOfWords = null;

	/**
	 * nazwa atrybutu dokumentu okreslajacego jego zawartosc.
	 */
	public static final String CONTENT_FIELD = "content";

	/**
	 * Nazwa atrybutu dokumentu okreslajacego jego nazwe.
	 */
	public static final String DOCUMENT_NAME_FIELD = "name";

	/**
	 * Nazwa atrybutu, przechowujaca klase podczas klasyfikacji
	 */
	public static final String DOCUMENT_CLASS_FIELD = "className";

	/**
	 * Pobiera unikalne ID dokumentu
	 * 
	 * @return ID
	 */
	public Long getId() {
		return id;
	}

	/**
	 * Ustawia unikalne ID dokumentu
	 * 
	 * @param id
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * Pobiera nazwe dokumentu
	 * 
	 * @return Nazwa dokumentu
	 */
	public String getName() {
		return name;
	}

	/**
	 * Usrawia nazwe dokumentu
	 * 
	 * @param name
	 *            Nazwa dokumentu.
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Pobiera date stworzenia dokumentu
	 * 
	 * @return Data stworzenia dokumentu.
	 */
	public Date getCreationDate() {
		return creationDate;
	}

	/**
	 * Ustawia date stworzenia dokumentu
	 * 
	 * @param creationDate
	 *            Data stworzenia dokumentu.
	 */
	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}

	/**
	 * Ustala czy dokument już zostal zaindeksowany przez aplikacje.
	 * 
	 * @return
	 */
	public boolean isIndexed() {
		return indexed;
	}

	/**
	 * Ustawia czy dokument byl indeksowany.
	 * 
	 * @param indexed
	 *            true - Indeksowany.
	 */
	public void setIndexed(boolean indexed) {
		if (!indexed) {
			indexingDate = null;
		}
		this.indexed = indexed;
	}

	/**
	 * Pobiera plik dokumentu.
	 * 
	 * @return
	 */
	public File getFile() {
		return file;
	}

	/**
	 * Ustawia plik dokumentu.
	 * 
	 * @param file
	 */
	public void setFile(File file) {
		this.file = file;
	}

	/**
	 * Pobiera date indeksowania.
	 * 
	 * @return Data indeksowania
	 */
	public Date getIndexingDate() {
		return indexingDate;
	}

	public void setIndexingDate(Date indexingDate) {
		if (indexingDate == null) {
			indexed = false;
		}
		this.indexingDate = indexingDate;
	}

	public DocumentType getType() {
		return type;
	}

	public void setType(DocumentType type) {
		this.type = type;
	}

	public Long getNumberOfWords() {
		return numberOfWords;
	}

	public void setNumberOfWords(Long numberOfWords) {
		this.numberOfWords = numberOfWords;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((creationDate == null) ? 0 : creationDate.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + (indexed ? 1231 : 1237);
		result = prime * result
				+ ((indexingDate == null) ? 0 : indexingDate.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result
				+ ((numberOfWords == null) ? 0 : numberOfWords.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Document other = (Document) obj;
		if (creationDate == null) {
			if (other.creationDate != null)
				return false;
		} else if (!creationDate.equals(other.creationDate))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (indexed != other.indexed)
			return false;
		if (indexingDate == null) {
			if (other.indexingDate != null)
				return false;
		} else if (!indexingDate.equals(other.indexingDate))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (numberOfWords == null) {
			if (other.numberOfWords != null)
				return false;
		} else if (!numberOfWords.equals(other.numberOfWords))
			return false;
		if (type != other.type)
			return false;
		return true;
	}

	@Override
	public String toString() {
		return file.getAbsolutePath();
	}

}
